package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbSellerMapper;
import com.dongdongshop.pojo.seller.TbSeller;
import com.dongdongshop.service.seller.SellerService;
import com.dongdongshop.util.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class SellerServiceImpl implements SellerService {

    @Autowired
    private TbSellerMapper tbSellerMapper;

    @Override
    public List<TbSeller> getSellerData(String name, String nickName, String status) {
        return tbSellerMapper.getSellerData(name,nickName,status);

    }

    @Override
    public TbSeller getSellerDetailed(String sellerId) {
        return tbSellerMapper.selectByPrimaryKey(sellerId);
    }

    @Override
    public List<TbSeller> getSeller1Data(String name, String nickName) {
        return tbSellerMapper.getSeller1Data(name,nickName);
    }

    @Override
    public void updateStatus(TbSeller tbSeller) {
        tbSellerMapper.updateByPrimaryKeySelective(tbSeller);
    }

    /*---------------------商家----------------------*/

    @Override
    public void registerSeller(TbSeller tbSeller) {
        String salt = ShiroUtils.generateSalt(4);
        tbSeller.setStatus("0");
        tbSeller.setPassword(ShiroUtils.encryptPassword("MD5", tbSeller.getPassword(), salt,1));
        tbSeller.setSalt(salt);
        tbSellerMapper.insertSelective(tbSeller);

    }
}
